package com.example.chasshelper;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.chasshelper.dao.ClassroomDao;
import com.example.chasshelper.dao.CourseDao;
import com.example.chasshelper.dao.MessageDao;
import com.example.chasshelper.dao.RegistrationDao;
import com.example.chasshelper.dao.SolutionDao;
import com.example.chasshelper.dao.StudentDao;
import com.example.chasshelper.dao.TeacherDao;
import com.example.chasshelper.dao.TestDao;
import com.example.chasshelper.model.Teacher;
import com.example.chasshelper.model.Test;
import com.example.chasshelper.utils.DaoUtils;

/*
 * 选择题展示页面
 * 从TestTeaAdapter跳转过来
 * */
public class MultipleChoiceTestActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = MultipleChoiceTestActivity.class.getSimpleName();
    private final Activity mContext = MultipleChoiceTestActivity.this;

    //控件
    private TextView tv_title;
    private TextView tv_content;
    private RadioGroup rg_option;
    private CheckBox cb_option1;
    private CheckBox cb_option2;
    private CheckBox cb_option3;
    private CheckBox cb_option4;
    private CheckBox cb_option5;
    private TextView tv_answer;
    private TextView tv_source;
    private ImageView iv_back;
    //数据
    private Test test;
    private Teacher teacher;
    //dao
    private TeacherDao teacherDao= DaoUtils.getTeacherDao();
    private StudentDao studentDao=DaoUtils.getStudentDao();
    private CourseDao courseDao=DaoUtils.getCourseDao();
    private ClassroomDao classroomDao=DaoUtils.getClassroomDao();
    private RegistrationDao registrationDao=DaoUtils.getRegistrationDao();
    private SolutionDao solutionDao = DaoUtils.getSolutionDao();
    private MessageDao messageDao = DaoUtils.getMessageDao();
    private TestDao testDao = DaoUtils.getTestDao();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multiple_choice_test);
        //初始化界面
        initUI();
        //初始化数据
        initData();
    }
    private void initUI() {
        //绑定控件
        tv_title = findViewById(R.id.tv_title);
        tv_content = findViewById(R.id.tv_content);
        rg_option = findViewById(R.id.rg_option);
        cb_option1 = findViewById(R.id.cb_option1);
        cb_option2 = findViewById(R.id.cb_option2);
        cb_option3 = findViewById(R.id.cb_option3);
        cb_option4 = findViewById(R.id.cb_option4);
        cb_option5 = findViewById(R.id.cb_option5);
        tv_answer = findViewById(R.id.tv_answer);
        tv_source = findViewById(R.id.tv_source);
        iv_back = findViewById(R.id.iv_back);
        //点击事件
        iv_back.setOnClickListener(this);
    }

    private void initData() {
        //接收数据
        test = (Test) getIntent().getSerializableExtra("test");
        teacher = testDao.findTeacher(test);
        //回显
        tv_title.setText(String.valueOf(test.getTestId()));
        tv_content.setText("（"+test.getTestType()+"）"+test.getTestContext());
        cb_option1.setText("A "+test.getTestItem1());
        cb_option2.setText("B "+test.getTestItem2());
        cb_option3.setText("C "+test.getTestItem3());
        if (Integer.valueOf(test.getTestItemNum()) >= 4) {
            cb_option4.setText("D "+test.getTestItem4());
        } else {
            cb_option4.setVisibility(View.INVISIBLE);
        }
        if (Integer.valueOf(test.getTestItemNum()) >= 5) {
            cb_option5.setText("E "+test.getTestItem5());
        } else {
            cb_option5.setVisibility(View.INVISIBLE);
        }
        tv_answer.setText("参考答案："+test.getTestAnswer());
        tv_source.setText("出题人："+teacher.getTeacherName());
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back://返回
                finish();
                break;

        }
    }

}